﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

public partial class wuc_login : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
    {
        string connStr = System.Configuration.ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
        SqlConnection conn = new SqlConnection(connStr);
        string queryString = "select Roles from KhachHang where Username=N'" + Login1.UserName + "' and Password=N'" + Login1.Password + "'";
        SqlCommand com = new SqlCommand(queryString,conn);
        conn.Open();
        SqlDataReader dr = com.ExecuteReader();
        if(dr.HasRows){
            dr.Read();
            string commaSeperatedRoles = dr.GetString(0);
            FormsAuthenticationUtil.RedirectFromLoginPage(Login1.UserName, commaSeperatedRoles, Login1.RememberMeSet);
        }
        else
        {
           return; 
        }
        conn.Close();
    }
}